home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10313 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.std.c,com[p.lang.std.c++
  4. Subject: Re: preprocessing question
  5. Date: 05 Mar 1996 14:40:05 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar5074005@qcd.lanl.gov>
  8. References: <313b9e9f.480978@NEWS.CLOUD9.NET>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: jalvo@cloud9.net's message of Tue, 05 Mar 1996 02:07:10 GMT
  13.  
  14. In article <313b9e9f.480978@NEWS.CLOUD9.NET>
  15. jalvo@cloud9.net (John G. Alvord) writes:
  16.  
  17. <snip>
  18. JGA:    #define XXX (1)
  19. JGA:    #include <stdio.h>
  20. JGA:    int main(void)
  21. JGA:    {
  22. JGA:        #if XXX
  23. JGA:            printf("Hello World!");
  24. JGA:        #endif
  25. JGA:        return 0;
  26. JGA:     }
  27. <snip>
  28. JGA: One compiler (SAS/C 5.50 cross compiler on AIX for MVS) complains
  29. that the #if 
  30. JGA: line is an illegal constant.  A close reading of the ANSI C
  31. standard document 
  32. JGA: reveals a clause that seems to imply (my reading) that a
  33. pre-processed series 
  34. JGA: of tokens that appear to be a preprocessing statement will be ignored. A
  35. JGA: coworker who is more experienced then me feels that the #if does not fall
  36. JGA: under that clause and the #if will be evaluated. His reasoning is that the
  37. JGA: preprocessed series of tokens is just a part of a preprocessing statement.
  38.  
  39. Don't read that close!
  40.  
  41. A line that begins with a # optionally preceded by whitespace is
  42. recognized as a preprocessing directive, and macro expansions are
  43. prohibited within it, except by special dispensation. The argument of
  44. #if has such special dispensation: but note that this preprocessing is
  45. done as a part of processing a pp-directive.
  46.  
  47. The statement in the standard is to prevent you from doing 
  48.  
  49. #define X #if XXX
  50. #define Y #endif
  51.  
  52. and then writing
  53.  
  54. X
  55. printf("Hello World!\n");
  56. Y
  57.  
  58. In any case (1) is a completely valid constant, so I have no idea what
  59. your compiler is complaining about. Does it compile `#if (1)'
  60. properly, or does it want `#if 1' instead?
  61.  
  62. Cheers
  63. Tanmoy
  64. --
  65. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  66. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  67. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  68. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  69. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  70. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  71.